﻿using System;
using fastCSharp;

namespace diantou.dataModel.path
{
    /// <summary>
    /// 网站默认路径配置
    /// </summary>
    public sealed class domain
    {
        /// <summary>
        /// 测试域名替换字符
        /// </summary>
        private char testChar = '1';
        /// <summary>
        /// 测试域名替换字符
        /// </summary>
        public byte TestCharCode
        {
            get { return testChar == '1' ? (byte)0 : (byte)testChar; }
        }
        /// <summary>
        /// 重定向域名集合
        /// </summary>
        public string[] LocationDomains;
        /// <summary>
        /// 主域名
        /// </summary>
        public string MainDomain = "51nod.com";
        /// <summary>
        /// 网站首页主域名
        /// </summary>
        public string HttpDomain;
        /// <summary>
        /// 网站首页主域名
        /// </summary>
        public string HttpsDomain;
        /// <summary>
        /// 网站首页主域名
        /// </summary>
        public string Domain;
        /// <summary>
        /// 图片文件域名
        /// </summary>
        public string ImageDomain;
        ///// <summary>
        ///// 图片文件域名
        ///// </summary>
        //public string HttpsImageDomain;
        /// <summary>
        /// 静态文件域名
        /// </summary>
        public string StaticFileDomain;
        ///// <summary>
        ///// 静态文件域名
        ///// </summary>
        //public string HttpsStaticFileDomain;
        /// <summary>
        /// 轮询域名
        /// </summary>
        public string PollDomain;
        /// <summary>
        /// 考试域名
        /// </summary>
        public string ExamDomain;
        /// <summary>
        /// 考试域名
        /// </summary>
        public string HttpsExamDomain;
        /// <summary>
        /// 网站默认路径配置
        /// </summary>
        private domain()
        {
            fastCSharp.config.pub.LoadConfig(this);
            MainDomain = MainDomain.replace('1', testChar);
            if (Domain == null) Domain = "www." + MainDomain;
            if (ImageDomain == null) ImageDomain = "img." + MainDomain;
            if (StaticFileDomain == null) StaticFileDomain = "file." + MainDomain;
            if (PollDomain == null) PollDomain = "comet." + MainDomain;
            if (ExamDomain == null) ExamDomain = "exam." + MainDomain;

            string https = testChar == '1' ? "https://" : "http://";
            if (HttpDomain == null) HttpDomain = "http://" + Domain + "/";
            if (HttpsDomain == null) HttpsDomain = https + Domain + "/";
            //if (HttpsImageDomain == null) HttpsImageDomain = https + ImageDomain + "/";
            //if (HttpsStaticFileDomain == null) HttpsStaticFileDomain = https + StaticFileDomain + "/";
            if (HttpsExamDomain == null) HttpsExamDomain = https + ExamDomain + "/";
        }
        /// <summary>
        /// 网站默认路径配置
        /// </summary>
        public static readonly domain Default = new domain();
    }
}
